package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapePick;
import com.ruoyi.grape.service.IGrapePickService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采收信息Controller
 * 
 * @author ld
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/grape/pick")
public class  GrapePickController extends BaseController
{
    @Autowired
    private IGrapePickService grapePickService;

    /**
     * 查询采收信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapePick grapePick)
    {
        startPage();
        List<GrapePick> list = grapePickService.selectGrapePickList(grapePick);
        return getDataTable(list);
    }

    /**
     * 导出采收信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:export')")
    @Log(title = "采收信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapePick grapePick)
    {
        List<GrapePick> list = grapePickService.selectGrapePickList(grapePick);
        ExcelUtil<GrapePick> util = new ExcelUtil<GrapePick>(GrapePick.class);
        util.exportExcel(response, list, "采收信息数据");
    }

    /**
     * 获取采收信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:query')")
    @GetMapping(value = "/{pickId}")
    public AjaxResult getInfo(@PathVariable("pickId") Long pickId)
    {
        return success(grapePickService.selectGrapePickByPickId(pickId));
    }

    /**
     * 新增采收信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:add')")
    @Log(title = "采收信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapePick grapePick)
    {
        return toAjax(grapePickService.insertGrapePick(grapePick));
    }

    /**
     * 修改采收信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:edit')")
    @Log(title = "采收信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapePick grapePick)
    {
        return toAjax(grapePickService.updateGrapePick(grapePick));
    }

    /**
     * 删除采收信息
     */
    @PreAuthorize("@ss.hasPermi('grape:pick:remove')")
    @Log(title = "采收信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pickIds}")
    public AjaxResult remove(@PathVariable Long[] pickIds)
    {
        return toAjax(grapePickService.deleteGrapePickByPickIds(pickIds));
    }
}
